package day12;

//volatile禁止重排序
public class Demo3 {
    static int a, b, c, d;

    public static void main(String[] args) throws InterruptedException {
        int i = 0;//计数的
        while (true) {
            i++;//计数
            a = b = c = d = 0;//每循环一次，数据清0
            Thread t1 = new Thread(() -> {
                a = 1;
                c = b;
            });
            Thread t2 = new Thread(() -> {
                b = 1;
                d = a;
            });
            t1.start();
            t2.start();

            t1.join();
            t2.join();
            if (c==0&&d==0){//重排序了
                System.out.println("执行第"+i+"次出现了重排序");
                break;
            }else {
                System.out.println(i);
            }
        }
    }
}
